package com.fuint.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.dto.ParamDto;
import com.fuint.common.service.SettingService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.mapper.MtSettingMapper;
import com.fuint.repository.model.MtSetting;
import com.fuint.utils.StringUtil;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 配置业务接口实现类
 *
 * Created by FSQ
 * CopyRight https://www.fuint.cn
 */
@Service
@AllArgsConstructor(onConstructor_= {@Lazy})//配置懒加载。使用Lombok注解@AllArgsConstructor生成全参构造函数，并通过onConstructor_= {@Lazy}配置构造函数为懒加载模式，延迟依赖注入。
public class SettingServiceImpl extends ServiceImpl<MtSettingMapper, MtSetting> implements SettingService {

    /**
     * 系统环境变量
     * */
    private Environment env;

    private MtSettingMapper mtSettingMapper;

    /**
     * 系统设置服务接口
     * */
    private SettingService settingService;


    @Override
    public void removeSetting(Integer merchantId, String type, String name) throws BusinessCheckException {

    }

    @Override
    public MtSetting saveSetting(MtSetting mtSetting) throws BusinessCheckException {
        return null;
    }

    @Override
    public List<MtSetting> getSettingList(Integer merchantId, String type) throws BusinessCheckException {
        return Collections.emptyList();
    }

    @Override
    public MtSetting querySettingByName(Integer merchantId, String type, String name) throws BusinessCheckException {
        return null;
    }

    @Override
    public MtSetting querySettingByName(Integer merchantId, Integer storeId, String type, String name) throws BusinessCheckException {
        return null;
    }

    /**
     * 获取系统上传文件的根路径
     *
     * @return 本地配置或阿里云的oss域名
     * */
    @Override
    public String getUploadBasePath() {
        String basePath = env.getProperty("images.upload.url");
        String mode = env.getProperty("aliyun.oss.mode");

        // 如果没设置模式就从上传本地，如果设置了mode=1就上传到阿里云oss
        if (mode==null){
            return basePath;
        }else {
            if (mode.equals("1")){
                String domain = env.getProperty("aliyun.oss.domain");
                if (StringUtil.isNotEmpty(domain)){
                    basePath=domain;
                }
            }
        }
        return basePath;
    }

    @Override
    public List<ParamDto> getPayTypeList(Integer merchantId, Integer storeId, String platform) throws BusinessCheckException {
        return Collections.emptyList();
    }
}
